<?php if (!defined('THINK_PATH')) exit();?>
<div class="row">
          <div class="col-lg-12">

            <div class="card">
			
              <div class="card-header"><h4>商品管理</h4>
			  
			  <div class="card-body">
                
                <form id="so" class="form-inline" action="" method="post" onsubmit="return false;">
                  <div class="form-group">
                    
                    <input class="form-control" type="text" id="example-if-email" name="word" placeholder="请输入关键词">
                  </div>
                  <div class="form-group">

					<a class="btn btn-label btn-primary"  id="sosend"><label><i class="mdi mdi-checkbox-marked-circle-outline"></i></label> 提交搜索</a>
                  </div>
                </form>
                
              </div>
				 
			  </div>
              <div class="card-body">
                
                <div class="table-responsive">
                  <table class="table table-bordered">
                    <thead>
                      <tr>
                        <th class="col-lg-1" >
                          编号
                        </th class="col-lg-1">
                        <th >主图</th>
                        <th>标题</th>
                        <th>销量</th>
                        <th>状态</th>
                        <th>操作</th>
						<th>备注</th>
                      </tr>
                    </thead>
                    <tbody>
					<?php if(is_array($data)): $i = 0; $__LIST__ = $data;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$v): $mod = ($i % 2 );++$i; $zorder = M('cash')->where('sid='.$v['id'])->sum('sum'); ?>
                      <tr>
                        <td><?php echo ($i); ?></td>
                        <td><a href="<?php echo ($v["img"]); ?>" target="_blank"><img width="50px" src="<?php echo ($v["img"]); ?>"></a></td>
                        <td><a href="<?php echo ($v["url"]); ?>" target="_blank"><?php if($v['name']){echo $v['name'];} else{echo '该商品还未采集';}?></a><br/>
							<code>采集时间：<?php echo date("Y-m-d H:i:s",$v['time']); ?></code>
						</td>

                        <td><?php if($zorder){echo $zorder;}else{echo 0;} ?></td>
                        <td>
						
						<a class=" type" href="javascript:void(0)" data="<?php echo ($v["id"]); ?>" >
						<?php
 if($v['type']==1){ echo '<span class="label label-success">上架中</span>';} else{ echo '<span class="label label-danger">已下架</span>';} ?>
						</a>
						</td>
                        <td>
                          <div class="btn-group">
                            <a class="btn btn-xs btn-default show" href="javascript:void(0)" data="<?php echo ($v["id"]); ?>" ><i class="mdi mdi-pencil"></i></a>
                            <a class="btn btn-xs btn-default delete" href="javascript:void(0)" data="<?php echo ($v["id"]); ?>"  ><i class="mdi mdi-window-close"></i></a>
                          </div>
                        </td>
						<td><?php echo ($v["con"]); ?></td>
                      </tr><?php endforeach; endif; else: echo "" ;endif; ?>
                    </tbody>
                  </table>
                </div>
                <ul class="pagination">
               <?php echo ($show); ?>
                </ul>
       
              </div>
            </div>
          </div>
          
        </div>
<script type="text/javascript">
  //删除
  $('.delete').click(function(){
  lightyear.loading('show');  // 显示
    $.ajax({
    type: "POST",
    url: "Home/del_shop", 
    data:'id='+$(this).attr("data"), 
      success: function(data){
	  lightyear.loading('hide');  // 隐藏    
        if(data.indexOf('操作成功')>=0){
		 lightyear.notify('操作成功', 'success', 500, 'mdi mdi-emoticon-happy', 'top', 'center');
		 setTimeout(function() {
		
          $.ajax({
          type: "POST",
          url: "/Home/shop.html",       
              success: function(data){
                      if(data){
							$("#content").html(data);
							
					  }else{
							alert('页面加载失败或异常,请刷新重试');
							lightyear.loading('hide'); 
					  }
              }
          });
					}, 1000);
        }else{
		 lightyear.notify(data, 'danger', 1000);
		}
      }
    });
  });
  
   //编辑
  $('.show').click(function(){
  lightyear.loading('show');  // 显示
    $.ajax({
    type: "POST",
    url: "Home/show/data/"+$(this).attr("data"), 
    success: function(data){
					lightyear.loading('hide');  // 隐藏    
					if(data){
							$("#content").html(data);
							lightyear.loading('hide');  // 隐藏
					  }else{
							alert('页面加载失败或异常,请刷新重试');
							lightyear.loading('hide'); 
					  }      }
    });
  });
  
 //改变状态
  $('.type').click(function(){
  lightyear.loading('show');  // 显示
    $.ajax({
    type: "POST",
    url: "Home/type/data/"+$(this).attr("data"), 
    success: function(data){
					lightyear.loading('hide');  // 隐藏    
					 if(data.indexOf('操作成功')>=0){
					  lightyear.notify('操作成功', 'success', 500, 'mdi mdi-emoticon-happy', 'top', 'center');
					  setTimeout(function() {
					  
					   $.ajax({
          type: "POST",
          url: "<?php echo ($_COOKIE["url"]); ?>",       
              success: function(data){
                      if(data){
							$("#content").html(data);
							
					  }else{
							alert('页面加载失败或异常,请刷新重试');
							lightyear.loading('hide'); 
					  }
              }
          });

					}, 100);
					  }else{
							alert('页面加载失败或异常,请刷新重试');
							lightyear.loading('hide'); 
					  }      }
    });
  });
  
     //分页
  $('.page').click(function(){
  lightyear.loading('show');  // 显示
    $.ajax({
    type: "POST",
    url: $(this).attr("data"), 
    success: function(data){
					lightyear.loading('hide');  // 隐藏    
					if(data){
							$("#content").html(data);
							lightyear.loading('hide');  // 隐藏
					  }else{
							alert('页面加载失败或异常,请刷新重试');
							lightyear.loading('hide'); 
					  }      }
    });
  });
  
//搜索
  $('#sosend').click(function(){
  lightyear.loading('show');  // 显示
    $.ajax({
    type: "POST",
	data:$('#so').serialize(), 
    url: 'Index/shop_so', 
    success: function(data){
					lightyear.loading('hide');  // 隐藏    
					if(data){
							$("#content").html(data);
							lightyear.loading('hide');  // 隐藏
					  }else{
							alert('页面加载失败或异常,请刷新重试');
							lightyear.loading('hide'); 
					  }      }
    });
  });
</script>